package thread;

public class MyTicket implements Runnable {
    private int tickets=100000;
    private synchronized int sellTicket() {
        if (tickets>0) {
            return tickets--;
        }else {
//            System.out.println("票已经卖完！");
            return -1;
        }
    }
    @Override
    public void run() {
        int n=0;
        while ((sellTicket()) > 0){
            n++;

        }
        System.out.println( Thread.currentThread().getName()+"窗口"+n+"张票");
    }


    public static void main(String[] args) {
        MyTicket mt=new MyTicket();
        Thread t1=new Thread(mt);
        Thread t2=new Thread(mt);
        Thread t3=new Thread(mt);
        Thread t4=new Thread(mt);
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
